package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.StudentLossItem;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.query.StudentLossItemQueryObj;
import cn.wolfcode.crm.service.IStudentLossItemService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("studentLossItem")
public class StudentLossItemController {

    @Autowired
    private IStudentLossItemService studentLossItemService;

    @RequestMapping("")
    @RequiresPermissions(value = {"学员流失首页","studentLossItem:index"} ,logical = Logical.OR)
    public String index(){

        return "studentLossItem/list";
    }

    @RequestMapping("list")
    @RequiresPermissions(value = {"学员流失列表","studentLossItem:list"} ,logical = Logical.OR)
    @ResponseBody
    public PageResult list(StudentLossItemQueryObj qo){
        PageResult result = studentLossItemService.query(qo);
        return result;
    }
    @RequestMapping("listData")
    @ResponseBody
    public Object listData(QueryObject qo){

        return studentLossItemService.list();
    }

    @RequestMapping("save")
    @RequiresPermissions(value = {"学员流失保存","studentLossItem:save"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult save(StudentLossItem entity){
        JSONResult result = new JSONResult();
        try{
            studentLossItemService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @RequiresPermissions(value = {"学员流失更新","studentLossItem:update"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult update(StudentLossItem entity){
        JSONResult result = new JSONResult();
        try{
            studentLossItemService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("已审核,不允许修改");
        }
        return result;
    }

    @RequestMapping("audit")
    @RequiresPermissions(value = {"学员流失审核","studentLossItem:audit"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult audit(Long id){
        JSONResult result = new JSONResult();
        try{
            studentLossItemService.audit(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("已审核 不允许操作");
        }
        return result;
    }


    @RequestMapping("delete")
    @RequiresPermissions(value = {"学员流失删除","studentLossItem:delete"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            studentLossItemService.delete(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }
}
